package me.obstsalat.guildera;

import java.util.TimerTask;

import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;

public class gt_villager_drop extends TimerTask {
	private guildera plugin;
	
	gt_villager_drop(guildera pl) {
		plugin = pl;
	}
	
	@Override
	public void run() {
		for(guild g : plugin.guilds) {
			for(Entity ent : plugin.overworld.getEntities()) {
				if(ent.getType() == EntityType.VILLAGER && g.isInGuild(ent.getLocation())) {
					double chance = Math.random();
					double c = 1 - plugin.config.getDouble("villager_drop_bread_chance");
					if(chance >= c) {
						plugin.overworld.dropItemNaturally(ent.getLocation(), new ItemStack(297));
					}
				}
			}
		}
	}
	
}
